#ifndef SOCKET_H
#define SOCKET_H

#pragma once
#include <string>
#include "sockAddrIn.hpp"
#include <iostream>
// 客户端和服务器都能用
class Socket
{
public:
    Socket(int fd): fd_(fd) {};
    // 默认构造函数会自动创建一个socket
    Socket();
    // void initAddr(const std::string& ip, const unsigned short port);
    ~Socket();
    bool Listen();
    bool Bind(const std::string& ip, const unsigned short port);
    void initAddr(const std::string& ip, const unsigned short port);
    // addr记录连接的客户端的地址，返回连接的套接字
    Socket* Accept(SockAddrIn* addr);
    int GetFd() { return fd_;}

    void setNonBlock();
    void setReusable();
    std::ostream& showInfo();
private:
    int fd_;
    SockAddrIn* addr_;

    std::string ip_;
    unsigned short port_;
};

#endif